﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.DataVisualization.Charting;
using dllLink;
using System.Threading;

namespace ASPGerant
{
    public partial class OPCVM : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            Chart[] tabChart = new Chart[11];
            tabChart[1] = ChartOPCVM1;
            tabChart[2] = ChartOPCVM2;
            tabChart[3] = ChartOPCVM3;
            tabChart[4] = ChartOPCVM4;
            tabChart[5] = ChartOPCVM5;
            tabChart[6] = ChartOPCVM6;
            tabChart[7] = ChartOPCVM7;
            tabChart[8] = ChartOPCVM8;
            tabChart[9] = ChartOPCVM9;
            tabChart[10] = ChartOPCVM10;

            //Nécessaire pour pouvoir utiliser SQL Server CE avec un site ASP
            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
            // Create new data series and set it's visual attributes
            Interface adaptater = new Interface();
            adaptater.connectBD();
            for (int i = 1; i <= 10; i++)
            {
                Series series = new Series(Interface.Naming[i]);
                series.ChartType = SeriesChartType.Line;
                series.BorderWidth = 3;
                series.ShadowOffset = 2;

                AdpDts result = adaptater.selectBD("Cotation, Date", "OPCVM" + i, "1=1 ORDER BY date asc");

                DataTable dt = result.dts.Tables[0];
                foreach (DataRow r in dt.Select())
                {
                    String date = r["Date"].ToString();
                    String[] test = date.Substring(0, 10).Split('/');
                    DateTime dateTimer = new DateTime(Convert.ToInt32(test[2]), Convert.ToInt32(test[1]), Convert.ToInt32(test[0]));

                    //DateTime dateTime = new DateTime(Convert.ToInt32(dates[2]), date.Split["/"][1], date.Split["/"][0]);
                    series.Points.AddXY(dateTimer, r["Cotation"]);
                }

                tabChart[i].Series.Add(series);
                tabChart[i].Series[Interface.Naming[i]]["ShowMarkerLines"] = "True";
                tabChart[i].ChartAreas["ChartArea1"].AxisX.LabelStyle.IsEndLabelVisible = true;
            }
            adaptater.disconnectBD();

        }

        public String dateMin(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            String temp = adapter.dateMinCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }

        public String dateMax(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            String temp = adapter.dateMaxCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }

        public Double firstCote(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            Double temp = adapter.firstCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }
        public Double lastCote(String OPCVM)
        {
            Interface adapter = new Interface();
            adapter.connectBD();

            Double temp = adapter.lastCoteBD(OPCVM);
            adapter.disconnectBD();
            return temp;
        }
    }
}
